package com.sanpu.kxe.business.main.presenter;

import com.sanpu.kxe.business.login.provider.ILoginProvider;
import com.sanpu.kxe.business.main.contract.SettingCenterContract;
import com.sanpu.kxe.business.main.view.SettingHostActivity;
import com.sanpu.kxe.module.dialog.MaterialDialog;
import com.sanpu.kxe.module.dialog.interfaces.OnBtnClickL;
import com.sanpu.kxe.utils.AppContextUtil;
import com.sanpu.kxe.utils.IntentTool;
import com.sanpu.kxe.utils.PublicProviderUtil;

/**
 * Description：设置中心
 * Created by 薛勇军 on 2018/7/12.
 */

public class SettingCenterPresenter implements SettingCenterContract.Presenter {

    private SettingCenterContract.View mView;

    private MaterialDialog mDialog;

    public SettingCenterPresenter(SettingCenterContract.View mView) {
        this.mView = mView;
    }

    @Override
    public void openUpdateLoginPwdActivity() {
        ILoginProvider provider = PublicProviderUtil.getProvider(ILoginProvider.class);
        if (provider != null) {
            provider.openUpdateLoginPwdActivity(mView.getContext());
        }
    }

    @Override
    public void openUpdatePayPwdActivity() {
        ILoginProvider provider = PublicProviderUtil.getProvider(ILoginProvider.class);
        if (provider != null) {
            provider.openUpdatePayPwdActivity(mView.getContext());
        }
    }

    @Override
    public void openModifyAccountActivity() {
        ILoginProvider provider = PublicProviderUtil.getProvider(ILoginProvider.class);
        if (provider != null) {
            provider.openModifyAccountActivity(mView.getContext());
        }
    }

    @Override
    public void exitApp() {
        if (mDialog == null) {
            mDialog = new MaterialDialog(mView.getContext())
                    .title("退出登录？")
                    .content("确定退出登录？")
                    .btnText("确定", "取消");
            mDialog.setOnBtnClickL(new OnBtnClickL() {
                @Override
                public void onBtnClick() {
                    mDialog.dismiss();
                    AppContextUtil.exit(mView.getContext());
                }
            }, new OnBtnClickL() {
                @Override
                public void onBtnClick() {
                    mDialog.dismiss();
                }
            });
        }
        if (!mDialog.isShowing())
            mDialog.show();
    }

    @Override
    public void openSettingHostActivity() {
        IntentTool.startActivity(mView.getContext(), SettingHostActivity.class);
    }

    @Override
    public void onDestroyPresenter() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
            mDialog = null;
        }
        if (mView != null) {
            mView = null;
        }
    }
}
